package com.harmontronics.hanma.paas.paas.domain.app.repository.persistence;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.harmontronics.hanma.paas.paas.domain.app.entity.valueobject.Fields;
import com.harmontronics.hanma.paas.paas.domain.app.repository.mapper.HmHttpRequestDefinitionMapper;
import com.harmontronics.hanma.paas.paas.domain.app.repository.po.HmHttpRequestDefinitionPO;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * @author ldb
 */
@Repository("hmHttpRequestDefinitionRepository")
public class HmHttpRequestDefinitionRepository extends ServiceImpl<HmHttpRequestDefinitionMapper, HmHttpRequestDefinitionPO> {

    public IPage<HmHttpRequestDefinitionPO> selectPage(QueryWrapper<HmHttpRequestDefinitionPO> queryWrapper, Page<HmHttpRequestDefinitionPO> page) {
        return baseMapper.selectPage(page, queryWrapper);
    }

    public HmHttpRequestDefinitionPO findByKeyInModel(String key, Long modelId) {
        QueryWrapper<HmHttpRequestDefinitionPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(Fields.KEY_DB, key);
        queryWrapper.eq(Fields.MODEL_ID, modelId);
        return baseMapper.selectOne(queryWrapper);
    }

    public List<HmHttpRequestDefinitionPO> findByModelId(Long modelId) {
        QueryWrapper<HmHttpRequestDefinitionPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(Fields.MODEL_ID, modelId);
        return baseMapper.selectList(queryWrapper);
    }
}